-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip masking non-strings #10
Conversation
test/index_test.js
Outdated
@@ -44,6 +45,11 @@ describe('maskXml()', () => { | |||
`); | |||
}); | |||
|
|||
it('should skip masking non-strings', () => { | |||
should.not.exist(maskXml(['foo', 'bar'])(undefined)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this (just a readability preference):
[undefined, { biz: 'baz' }].forEach(value => {
maskXml(['foo', 'bar'])(value).should.eql(value);
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fails with a TypeError: Cannot read property 'should' of undefined
, but this works:
[undefined, { biz: 'baz' }].forEach(value => {
should(maskXml(['foo', 'bar'])(value)).eql(value);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Included other minor improvements too.
70b8eeb
to
e86fc35
Compare
@@ -44,6 +45,12 @@ describe('maskXml()', () => { | |||
`); | |||
}); | |||
|
|||
it('should skip masking non-strings', () => { | |||
[undefined, { biz: 'baz' }, 42].forEach(nonString => { | |||
should(maskXml(['foo'])(nonString)).equal(nonString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the syntax <object>.should…
when possible please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would also fail with a TypeError: Cannot read property 'should' of undefined
When providing an
undefined
parameter to the masking function (or any non-string for that matter), aTypeError
is thrown ("TypeError: Cannot read property 'replace' of undefined"). The changes introduced by this PR will make the function simply return the original parameter when it's not a string.